home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / bbs / callf.zip / CALLF.C next >
C/C++ Source or Header  |  1990-04-11  |  5KB  |  271 lines

  1.  
  2. #include <time.h>
  3.  
  4. void set_baud_rate(int, int);
  5. int request_status(int);
  6. int initialize_driver(int);
  7. void deinitialize_driver(int);
  8. void raise_lower_dtr(int, int);
  9. void flush_output_buffer(int);
  10. void flow_control(int, int);
  11. int read_block(int, char *, int);
  12. int write_block(int, char *, int);
  13.  
  14. void write_string(int, char *);
  15. void write_byte(int, int);
  16. void delay(int);
  17.  
  18.  
  19. char text11[] = { "\n"
  20.     "1. Enter the phone number you wish to call, followed by a RETURN.\n"
  21.     "   You may use the \"-\" for clarity if you wish. EXAMPLE: 555-1212 (rtn)\n"
  22.     "\n"
  23.     "2. Wait about five seconds and call " };
  24.  
  25. char text12[] = { " again.\n"
  26.     "\n"
  27.     "   NOTE:\n"
  28.     "   If you are calling a voice line, don't forget to pick up the reciever\n"
  29.     "   and turn off the MODEM after the phone starts to ring.\n"
  30.     "\n"
  31.     "   If you're calling another BBS line, everthing will work the same as\n"
  32.     "   it does when you call this system.\n"
  33.     "\n"
  34.     "\n"
  35.     "Enter the number you wish to call: <555-1212 c/r> " };
  36.  
  37. char text21[] = {
  38.     "\n"
  39.     "Now hang up, wait five seconds, and call " };
  40.  
  41. char text22[] = { " again.\n"
  42.     "\n\n" };   
  43.  
  44. char help[] = {
  45.     "\n"
  46.     "    CALLF <port> <phone #> <set> <reset>\n"
  47.     "\n"
  48.     "    <port> is 1=COM1 or 2=COM2\n"
  49.     "    <phone #> is your phone number for them to call back.\n"
  50.     "    <set> is the phone code to set call forwarding.  Ex: ATDT72#,\n"
  51.     "    <reset> is the phone code to reset call forwarding.  Ex: ATDT73#\n"
  52.     "\n" };
  53.  
  54.  
  55. main(argc, argv)
  56.   int argc;
  57.   char *argv[];
  58. {
  59.     int i;
  60.     int port;
  61.     char phone[9];
  62.  
  63.     printf("Call Forwarding by Daniel Hilderbrand.  343/5\n");
  64.  
  65.     if (argc < 5 )
  66.     {
  67.         printf(help);
  68.         exit(1);
  69.     }
  70.  
  71.     if ((argv[1][0] < '1') || (argv[1][0] > '2'))
  72.     {
  73.         printf("\nInvalid port number.  Must be 1=com1 or 2=com2\n");
  74.         printf(help);
  75.         exit(1);
  76.     }
  77.  
  78.     port = argv[1][0] - '0' - 1;
  79.     printf("port %d\n", port);
  80.  
  81.     if (initialize_driver(port) < 28)
  82.     {
  83.         printf("This driver is not a high enuf version.\n");
  84.         raise_lower_dtr(port, 0);
  85.         deinitialize_driver(port);
  86.         exit(1);
  87.     }
  88.  
  89.     flow_control(port, 0);
  90. /*    set_baud_rate(port, 0x83); */
  91.  
  92.     write_string(port, text11);
  93.     write_string(port, argv[2]);
  94.     write_string(port, text12);
  95.  
  96.     if (input_phone_number(port, phone) < 8)
  97.     {
  98.         if ((request_status(port) & 0x0080) != 0)
  99.         {
  100.             write_string(port, "\n    Invalid phone number - try again\n");
  101.             delay(5);
  102.             flush_output_buffer(port); 
  103.         }
  104.         raise_lower_dtr(port, 0);
  105.         exit(0);
  106.     }
  107.  
  108.     write_string(port, text21);
  109.     write_string(port, argv[2]);
  110.     write_string(port, text22);
  111.  
  112.     delay(5);
  113. /*    flush_output_buffer(port); */
  114.     raise_lower_dtr(port, 0);
  115.  
  116.  
  117. /*
  118. **    Now do call forwarding stuff.
  119. */
  120.  
  121.     for (i=0; i<2; i++)
  122.     {
  123.         delay(2);
  124.         raise_lower_dtr(port, 1);
  125.         delay(1);
  126.  
  127.         write_string(port, argv[3]);
  128.         write_string(port, phone);
  129.         write_byte(port, 13);
  130.         printf("\n");
  131.  
  132.         delay(7);
  133.         flush_output_buffer(port); 
  134.         raise_lower_dtr(port, 0);
  135.     }
  136.  
  137.     delay(70);
  138.  
  139.     for (i=0; i<2; i++)
  140.     {
  141.         delay(1);
  142.         raise_lower_dtr(port, 1);
  143.         delay(1);
  144.  
  145.         write_string(port, argv[4]);
  146.         write_byte(port, 13);
  147.         printf("\n");
  148.  
  149.         delay(7);
  150.         flush_output_buffer(port); 
  151.         raise_lower_dtr(port, 0);
  152.     }
  153.  
  154.     deinitialize_driver(0);
  155. }
  156.  
  157. /*
  158. **    Get phone number.
  159. */
  160. int input_phone_number(port, ptr)
  161.   int port;
  162.   char *ptr;
  163. {
  164.     int c;
  165.     int len;
  166.     c = 0;
  167.     len = 0;
  168.  
  169.     while (1)
  170.     {
  171.         while(read_block(port, ((char *) &c), 1) <= 0)
  172.             if ((request_status(port) & 0x0080) == 0)
  173.                 return(0);
  174.  
  175.         if (len == 3)
  176.         {
  177.             *ptr++ = '-';
  178.             len++;
  179.             write_block(port, "-", 1);
  180.             printf("-");
  181.         }
  182.  
  183.         switch (c)
  184.         {
  185.           case 13:
  186.             *ptr = 0;
  187.             write_byte(port, 13);
  188.             write_byte(port, 10);
  189.             return(len);
  190.  
  191.           case 8:
  192.           case 127:
  193.             if (len > 0)
  194.             {
  195.                 write_byte(port, 8);
  196.                 write_byte(port, ' ');
  197.                 write_byte(port, 8);
  198.                 len--;
  199.                 ptr--;
  200.             }
  201.             break;
  202.  
  203.           case '0':
  204.             if ((len > 0) && (len < 8))
  205.             {
  206.                 *ptr++ = c;
  207.                 len++;
  208.                 write_byte(port, c);
  209.             }              
  210.             break;
  211.  
  212.           case '1':
  213.             if ((len > 0) && (len < 8))
  214.             {
  215.                 *ptr++ = c;
  216.                 len++;
  217.                 write_byte(port, c);
  218.             }              
  219.             break;
  220.  
  221.           default:
  222.             if ((c >= '0') && (c <= '9') && (len < 8))
  223.             {
  224.                 *ptr++ = c;
  225.                 len++;
  226.                 write_byte(port, c);
  227.             }
  228.         }
  229.     }
  230. }
  231.  
  232. void delay(sec)
  233.   int sec;
  234. {
  235.     int i;
  236.     long last_time;
  237.  
  238.     for(i=0; i<sec; i++)
  239.     {
  240.         last_time = ((long) time(0));
  241.         while(last_time == ((long) time(0)))
  242.             ;
  243.     }
  244. }
  245.  
  246.  
  247.  
  248. void write_string(port, ptr)
  249.   int port;
  250.   char *ptr;
  251. {
  252.     while (*ptr != 0)
  253.         if (*ptr == '\n')
  254.         {
  255.             write_byte(port, 13);
  256.             write_byte(port, 10);
  257.             ptr++;
  258.         }
  259.         else
  260.             write_byte(port, *ptr++);
  261. }
  262.  
  263. void write_byte(port, c)
  264.   int port, c;
  265. {
  266.     while (write_block(port, ((char *) &c), 1) != 1)
  267.         if ((request_status(port) & 0x0080) == 0)
  268.             break;
  269.     printf("%c", c);
  270. }
  271.